<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <a-input placeholder="请输入项目名称" v-model="queryParam.xmmc"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="姓名">
              <a-input placeholder="请输入姓名" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目单状态">
              <j-dict-select-tag v-model="queryParam.status" placeholder="请选择项目单状态" dictCode="xmd_status"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="项目编号">
                <a-input placeholder="请输入项目编号" v-model="queryParam.xmbh"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="项目单号">
                <a-input placeholder="请输入项目单号" v-model="queryParam.itembh"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="5" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 共计 <a style="font-weight: 600">{{ jszt.all }}</a> 单：
        <i style="margin-left: 26px;"></i> 待承接 <a style="font-weight: 600">{{ jszt.dcj }}</a> 单
        <i style="margin-left: 26px;"></i> 进行中 <a style="font-weight: 600">{{ jszt.jxz }}</a> 单
        <i style="margin-left: 26px;"></i> 验收被驳回 <a style="font-weight: 600">{{ jszt.ysbbh }}</a> 单
        <i style="margin-left: 26px;"></i> 待平台验收 <a style="font-weight: 600">{{ jszt.dptys }}</a> 单
        <i style="margin-left: 26px;"></i> 待企业验收 <a style="font-weight: 600">{{ jszt.dqyys }}</a> 单
        <i style="margin-left: 26px;"></i> 待结算 <a style="font-weight: 600">{{ jszt.djs }}</a> 单
        <i style="margin-left: 26px;"></i> 结算锁定中 <a style="font-weight: 600">{{ jszt.jssdz }}</a> 单
        <i style="margin-left: 26px;"></i> 已完成 <a style="font-weight: 600">{{ jszt.ywc }}</a> 单
      </div>
      <!--<div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
      <!--  <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
      <!--  <i style="margin-left: 26px;"></i> 累计完成的结算金额为 <a style="font-weight: 600">{{ jsjeSum }}</a>元-->
      <!--  <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      <!--</div>-->
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleAudit(record)">验收</a>
        </span>
      </a-table>
    </div>

    <a-modal
      title="查看验收单"
      :visible="visibleHz"
      width="1000px"
      cancelText="关闭"
      @cancel="HzClose"
      :okButtonProps="{ class:{'jee-hidden': true} }"
    >
      <div  id="hz" style="width:960px;height:600px;">
        <iframe style="width: 100%;height: 100%;" :src="hzImgUrl"></iframe>
      </div>
    </a-modal>

    <plat-ys-project-modal ref="modalForm" @ok="modalFormOk"></plat-ys-project-modal>
  </a-card>
</template>

<script>

  import { httpAction, getAction, postAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import PlatYsProjectModal from './modules/PlatYsProjectModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'

  export default {
    name: 'PlatYsProjectList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDictSelectTag,
      PlatYsProjectModal,
    },
    data () {
      return {
        description: '待验收项目单列表',
        queryParam: {
            xmmc: '',
            xmbh: '',
            xmlxid: '',
            itembh: '',
            name: '',
        },
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:40,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
              title:'企业名称',
              align:"center",
              dataIndex: 'gsmc'
          },
          {
              title:'项目编号',
              align:"center",
              dataIndex: 'xmbh'
          },
          {
              title:'项目协议编号',
              align:"center",
              dataIndex: 'xmxybh'
          },
          {
              title:'项目名称',
              align:"center",
              dataIndex: 'xmmc'
          },
          {
            title:'发布时间',
            align:"center",
            dataIndex: 'fbsj',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:87,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/project/lhygProjectIndividual/queryPlYsLpi",
          getYsdSum: "/project/lhygProjectIndividual/platYsdSum",
        },
        dictOptions:{},
        jsjeSum: 0,
        visibleHz: false,
        hzImgUrl: '',
        jszt: {
          all: 0,
          dcj: 0,
          jxz: 0,
          ysbbh: 0,
          dptys: 0,
          dqyys: 0,
          djs: 0,
          jssdz: 0,
          ywc: 0
        },
      }
    },
    created() {
      this.getYsdSum();
    },
    computed: {
    },
    methods: {
      initDictConfig(){
      },
      handleAudit(record){
          //record.ystype = ystype;
          this.$refs.modalForm.audit(record);
          this.$refs.modalForm.title = "验收";
          this.$refs.modalForm.disableSubmit = false;
      },
      onSelectChange(selectedRowKeys, selectionRows) {
          this.selectedRowKeys = selectedRowKeys;
          this.selectionRows = selectionRows;
          let fkjeSum = 0
          selectionRows.forEach((item,i) => {
              if(item.status == 8) {
                  fkjeSum = parseFloat(fkjeSum) + parseFloat(item.fkje);
              }
          })
          this.jsjeSum = fkjeSum.toFixed(2);
      },
      onClearSelected() {
          this.jsjeSum = 0;
          this.selectedRowKeys = [];
          this.selectionRows = [];
      },
      viewYsd(record){
          this.hzImgUrl = record.ysdpdf;
          this.visibleHz = true;
      },
      HzClose(){
          this.visibleHz = false;
      },
      getYsdSum() {
        let that = this;
        getAction(that.url.getYsdSum, null).then(res => {
          if (res.success) {
            that.jszt = res.result;
          }
        }).catch((e) => {
          that.$message.warning(res.message);
        });
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>